//
//  XLGendQueueManager.h
//  Etion
//
//  Created by  user on 11-4-19.
//  Copyright 2011 GuangZhouXuanWu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XLGSendQueueIndex.h"

#import "XLGSendQueueEnum.h"

#import "XLGSendQueuePoolItem.h"

#define		WFOBJE				@"wfobj"
#define		WSDSKVE				@"wsdskv"
#define		WSAFFAIRKVE			@"wsaffairkv"
#define		WSIMAGEE			@"wsimage"
#define		WSRADIOE			@"wsradio"
#define		WSMULTIMEDIA        @"wsmultimedia"

extern NSString *const XLGSendQueueManagerBackgroundMaintainKey;

extern NSString *const XLGSendQueueDefaultDBFile;

extern NSString *const XLGSendQueueDataFolder;

extern NSString *const XLGSendQueueManagerDefaultKey;

@class XLGSendQueueManager;
@class XLGSendItem;
@class XLGManagerService;

@protocol XLGSendItemDelegate <NSObject>

@optional
- (void)sendItem:(XLGSendItem *)item totalWillSendBytes:(NSUInteger)bytes;

- (void)sendItem:(XLGSendItem *)item hadSendedBytes:(NSUInteger)bytes;

- (void)sendItem:(XLGSendItem *)item updateSendingFile:(NSString *)szName;

- (void)sendItem:(XLGSendItem *)item willSendFileNumsAtIndex:(NSUInteger)index totleNum:(NSUInteger)num fileName:(NSString *)name;

@end

@interface XLGSendItem : XLGSendQueuePoolItem
{
}

@property(nonatomic, readonly) XLGSendQueueIndex *mi;
@property(nonatomic, readonly) NSString *currentSendingFile;
@property(nonatomic, readonly) NSUInteger nHadsendedbytes;
@property(nonatomic, readonly) NSUInteger nTotalwillsendbytes;

- (void)addSendItemDelegate:(id <XLGSendItemDelegate>)obj;

- (void)removeSendItemDelegate:(id <XLGSendItemDelegate>)obj;

- (void)removeAllSendItemDelegate;

- (void)sendItemSuccessCategoryOpeateion:(NSString *)szExtendid;

- (XLGResult*)sendItemDataFormatCategoryOpeateion:(NSString *)extendID sendType:(NSUInteger)sendType textCache:(NSString *)textCacheFilePath multiMediaCache:(NSString *)mediaCacheFilePath messageManagerAttach:(XMSDataOperationManager *)attach;

@end

@protocol XLGSendQueueManagerDelegate <NSObject>

- (void)exchangeManager:(XLGSendQueueManager *)manager sendItemStatus:(XLGSendItem *)senditem;

@optional

- (void)exchangeManager:(XLGSendQueueManager *)manager allSendItemStatus:(XLGSendItemStatusType)oldType toNewType:(XLGSendItemStatusType)newtype;

@end

@protocol XLGSendQueueProgressViewDelegate <NSObject>

- (void)sendQueue:(XLGSendQueueManager *)manager beginProgressView:(NSString *)funName;

- (void)sendQueueEndProgressView;

@end

@interface XLGSendQueueManager : NSObject
{
}

@property(nonatomic,assign) NSUInteger maxSendingCount;
@property(nonatomic,assign) NSTimeInterval resendIntervalTime;
@property(nonatomic,readonly) NSUInteger sendQueueCount;

- (void)addSendQueueManagerDelegate:(id <XLGSendQueueManagerDelegate>)obj;

- (void)removeSendQueueManagerDelegate:(id <XLGSendQueueManagerDelegate>)obj;

- (void)addSendItem:(XLGSendQueueIndex *)mi;

- (void)addSendItem:(XLGSendQueueIndex *)mi uiTarget:(id)target;

- (void)getFinishSendItemsAsyncCompletion:(void (^)(NSArray *finishedItems))completion;

- (void)getFinishSendIndex:(NSString*(^)(NSString *condition))condition asynCompletion:(void(^)(NSArray *finishedItems))completion;

/**
 *  删除已经完成的发送任务，界面不能调用此方法
 *
 *  @param arGuid 任务id，NSString array
 */
- (void)deleteFinishSendItems:(NSArray *)arGuid;

//id string array
- (void)deleteFinishSendItems:(NSArray *)arGuid asyncCompletion:(void (^)())completion;

- (void)deleteAllFinishSendItemsAsyncCompletion:(void (^)())completion;

- (void)deleteSendIndex:(NSString *(^)(NSString *))condition asyncCompletion:(void (^)())completion;

/**
 *  删除发送队列中，除发送完成的任务，界面不能调用此方法
 *
 *  @param extendid 要删除的任务id
 *
 *  @return 返回
 */
- (NSInteger)deleteSendQueueItem:(NSString*)extendID;

- (void)delete:(NSString*)extendID delegate:(id <XLGSendQueueProgressViewDelegate>)delegate asyncCompletion:(void (^)(NSInteger nResult))completion;

- (void)stop:(NSString*)extendID delegate:(id <XLGSendQueueProgressViewDelegate>)delegate asyncCompletion:(void (^)(NSInteger nResult))completion;

- (void)resend:(NSString*)extendID delegate:(id <XLGSendQueueProgressViewDelegate>)delegate asyncCompletion:(void (^)(NSInteger nResult))completion;

- (void)upPriority:(NSString*)extendID delegate:(id <XLGSendQueueProgressViewDelegate>)delegate asyncCompletion:(void (^)(NSInteger nResult))completion;

- (void)terminalSendingItemWithSendItemID:(NSString*)sendItemID;

- (NSInteger)sendAllFaildItem;

- (void)enumeSendItem:(void (^)(NSUInteger nIndex, BOOL bIsend, XLGSendItem *item, BOOL *bStop))block;


+ (void)initSendQueueManager;

+ (XLGSendQueueManager *)sendQueueManager;

+ (void)initMultiSendQueueManagerWithKey:(NSArray*)keys DBName:(NSArray*)DBNames;

+ (XLGSendQueueManager *)sendQueueManager:(NSString*)key;

+ (void)releaseSendQueueManager;


+ (NSInteger)resumeSendQueueManager;

+ (void)suspendSendQueueManager;

@end
